package com.candoit.webapps.pricing.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "perfiles")
public class Perfil implements Serializable {

	private static final long serialVersionUID = -4125206502794928868L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id")
	private Integer id;
	
	@Column(name = "descripcion")
	private String descripcion;
	
	@Column(name = "activo")
	private boolean activo;
	
	@Column(name = "import_cc")
	private boolean importCC;
	
	@Column(name = "import_cca")
	private boolean importCCA;
	
	@Column(name = "calculate_cut")
	private boolean calculateCUT;
	
	@Column(name = "admin_lin_form")
	private boolean adminLimForm;
	
	@Column(name = "admin_profiles")
	private boolean adminProfiles;
	
	@Column(name = "admin_users")
	private boolean adminUsers;
	
	@ManyToMany
	@JoinTable(name="perfil_rol",
	  			joinColumns=
	  					@JoinColumn(name="id_perfil", referencedColumnName="id"),
	  					inverseJoinColumns=@JoinColumn(name="id_rol", referencedColumnName="id")
	        	)
	private List<Rol> roles;
	
	@Transient
	private String activoMsg;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getDescripcion() {
		return descripcion;
	}

	public void setDescripcion(String descripcion) {
		this.descripcion = descripcion;
	}
	
	public boolean isActivo() {
		return activo;
	}

	public void setActivo(boolean activo) {
		this.activo = activo;
	}

	public boolean isImportCC() {
		return importCC;
	}

	public void setImportCC(boolean importCC) {
		this.importCC = importCC;
	}

	public boolean isImportCCA() {
		return importCCA;
	}

	public void setImportCCA(boolean importCCA) {
		this.importCCA = importCCA;
	}

	public boolean isCalculateCUT() {
		return calculateCUT;
	}

	public void setCalculateCUT(boolean calculateCUT) {
		this.calculateCUT = calculateCUT;
	}

	public boolean isAdminLimForm() {
		return adminLimForm;
	}

	public void setAdminLimForm(boolean adminLimForm) {
		this.adminLimForm = adminLimForm;
	}

	public boolean isAdminProfiles() {
		return adminProfiles;
	}

	public void setAdminProfiles(boolean adminProfiles) {
		this.adminProfiles = adminProfiles;
	}

	public boolean isAdminUsers() {
		return adminUsers;
	}

	public void setAdminUsers(boolean adminUsers) {
		this.adminUsers = adminUsers;
	}
	
	public String getActivoMsg() {
		if (activo){
			return "Si";
		}else{
			return "No";
		}
	}

	public void setActivoMsg(String activoMsg) {
		this.activoMsg = activoMsg;
	}
	
	public List<Rol> getRoles() {
		return roles;
	}

	public void setRoles(List<Rol> roles) {
		this.roles = roles;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Perfil && ((Perfil)obj).getId().equals(this.id)){
			return true;
		}
		return false;
	}
	
	
	

}
